<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page errorPage="../errorPage.jsp" %>
<c:if test="${empty sessionScope.user}">
	<c:redirect url="../login.jsp" />
</c:if>
<c:if test="${sessionScope.user.getClass().name != 'accountManagement.Admin'}">
	<jsp:forward page="../errorPage.jsp">
		<jsp:param name="error" value="Access not permitted!" />
	</jsp:forward>
</c:if>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="ISO-8859-1">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/template.css">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/header.css">
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/footer.css">
		<title>Ricerca account</title>
	</head>
	<body>
		<div id="body">
			<%@ include file="../header.jsp" %>
			
			<%@ include file="../menu.jsp" %>
			
			<div id="title">
				Ricerca account
			</div>
			
			<div id="content">
				<div>
					<form action="${pageContext.request.contextPath}/ServletSearchAccount" method="post">
						<div>
							<label>Nickname:</label>
							<input type="text" id="nickname" name="nickname">
						</div>
						<div>
							<input type="submit" id="ricerca" name="ricerca" value="Cerca Account">
						</div>
					</form>
				</div>
				
				<div>
					<table>
						<thead>
							<tr>
								<th>Nickname</th>
								<th>Tipo</th>
								<th colspan="2">Comandi</th>
							</tr>
						</thead>
						<tbody>
						<c:forEach var="account" items="${accountList}">
							<tr>
								<td>${account.nickname}</td>
								<td>${account.getClass().simpleName}</td>
								<td>
									<a href="${pageContext.request.contextPath}/ServletRemoveAccount?nickname=${account.nickname}">
										<img src="${pageContext.request.contextPath}/img/delete.png" alt="Elimina" title="Elimina">
									</a>
								</td>
								<td>
									<a href="${pageContext.request.contextPath}/ServletViewAccountDetails?nickname=${account.nickname}">
										<img src="${pageContext.request.contextPath}/img/details.gif" alt="Visualizza dettagli" title="Visualizza dettagli">
									</a>
								</td>
							</tr>
						</c:forEach>
						<c:if test="${accountList.size() == 0}" >
							<tr><td colspan="4">Nessun elemento rispetta i parametri della ricerca</td></tr>
						</c:if>
						</tbody>
					</table>
				</div>
			</div>
			
			<%@ include file="../footer.jsp" %>
		</div>
	</body>
</html>